import {createRouter, createWebHistory} from 'vue-router'
import myindex from '../components/myindex.vue'
import home from '../components/home.vue'
import liao from '../components/liao.vue'
import kefu from '../components/kefu.vue'
import succeed from '../components/succeed.vue'
import UpdateUserData from "@/components/UpdateUserData.vue";
import shezhi from '../components/shezhi.vue'
import Homeindex from "@/components/Homeindex.vue";
import MessageView from "@/components/MessageView.vue";
import VideoView from "@/components/VideoView.vue";
import echartsTest from "@/components/echartsTest.vue";
import MyView from "@/components/MyView.vue";
import EssayDetail from "@/components/EssayDetail.vue";
import videodetails from "@/components/VideoDetails.vue";


const routes = [{
    path: '/login',
    name: 'index',
    component: myindex
},
    {
        path: '/',
        name: 'home',
        component: home,
        children: [
            {
                path: '/homeindex',
                name: 'Homeindex',
                component: Homeindex
            },
            {
                path: '/message',
                name: 'MessageView',
                component: MessageView
            },
            {
                path: '/video',
                name: 'videoview',
                component: VideoView
            },
            {
                path: '/myview',
                name: 'myview',
                component: MyView
            },

        ]
    }, {
        path: '/success',
        name: 'LoginSuccess',
        component: succeed
    }, {
        path: '/userdata',
        name: 'UpdateUserData',
        component: UpdateUserData
    }, {
        path: '/shezhi',
        name: 'shezhi',
        component: shezhi
    }, {
        path: '/echarts',
        name: 'echarts',
        component: echartsTest
    }, {
        path: '/kefu',
        name: 'kefu',
        component: kefu
    },{
        path: '/essaydetail',
        name: 'essaydetail',
        component: EssayDetail
    },{
        path: '/liao',
        name: 'liao',
        component: liao
    },{
        path: '/videodetails',
        name: 'videodetails',
        component: videodetails
    },
    // 其他路由...
]

const router = createRouter({
    history: createWebHistory(""),
    routes
})

// router.beforeEach((to, from, next) => {
//     var reslist = ['/login', '/register', '/home']
//     if (reslist.indexOf(to.path) == -1) {
//         var token = localStorage.getItem('token')
//         token = 123
//         if (token) {
//             //验证是否在权限列表中
//             var menulist = localStorage.getItem('mpromition')
//             if (menulist) {
//                 var mlist = JSON.parse(menulist)
//                 if (mlist.indexOf(to.path) >= 0) {
//                     next()
//                 } else {
//                     alert("无权访问此页面")
//                     next({ "name": 'Login' })
//                 }
//             } else {
//                 alert("无权访问")
//             }

//         } else {
//             next({ "name": 'Login' })
//         }
//     }
//     next()
// })


export default router